﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class Solution14
    {
        public int BinarySearch(int[] nums,int target)
        {
            Array.Sort(nums);
            int left = 0;
            int right = nums.Length - 1;
            while (left<=right)
            {
                int mid = (left + right) / 2;
                if (nums[mid] == target)
                {
                    return mid;
                }
                else if (nums[mid] > target)
                {
                    right--;
                }
                else
                {
                    left++;
                }
            }
            return -1;
        }
    }
}
